<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    // var a = function(){
    //   String.protoytype.trim = function() {
    //     return this.replace(/^\s+/,"").replace(/\s+$/,"")
    //   }
    // }
    //深拷贝，利用json复制
    function b() {
      var oldObj = "sdf";
      var newObj = JSON.parse(JSON.stringify(oldObj));
      console.log(newObj)
    }

    //写一个类似trim的方法
    function c() {
      var oldObj = " s df ";
      var newObj = oldObj.trim();
      console.log(oldObj)
      console.log(newObj)
      console.log(ownTrim(oldObj))
    }
    function ownTrim(str) {
      if( str && typeof str === "string") {
        return str.replace(/(^\s*)|(\s*)$/g,"")
      }
    }
    c()

  </script>
</body>
</html>